<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="org.apak.model.*" import="org.apak.control.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Service device</title>
</head>
<body>
<%
	ServiceDeviceStatusType[] serviceDeviceStatusTypeArray = (ServiceDeviceStatusType[]) request.getAttribute("serviceDeviceStatusTypeArray");

	ServiceDevice serviceDevice = (ServiceDevice) request.getAttribute("serviceDevice");
	ErrorList errors = (ErrorList) request.getAttribute("errors");
	String success = (String) request.getAttribute("success");
	String serviceOrderID = (String) request.getAttribute("serviceOrderID");
	ServiceDeviceForm serviceDeviceForm = (ServiceDeviceForm) request.getAttribute("serviceDeviceForm");
	String[] fields = {"", "0", ""};
	String[] errorsText = {"", "", ""};
	if(errors != null) {
		serviceDeviceForm = (ServiceDeviceForm) errors.getForm();
		fields[0] = serviceDeviceForm.getDeviceName();
		fields[1] = serviceDeviceForm.getService_device_status_type_fk();
		fields[2] = serviceDeviceForm.getService_description();
		errorsText[0] = errors.getError("device_name");
	} else if(serviceDeviceForm != null) {
		fields[0] = serviceDeviceForm.getDeviceName();
		fields[1] = serviceDeviceForm.getService_device_status_type_fk();
		fields[2] = serviceDeviceForm.getService_description();
	}  else if(serviceDevice != null) {
		fields[0] = serviceDevice.getDeviceName();
		fields[1] = Integer.toString(serviceDevice.getService_device_status_type_fk());
		if(serviceDevice.getService_description() == null)
			fields[2] = "";
		else
			fields[2] = serviceDevice.getService_description();
		
	}
	if(success == null)
		success = "";
%>
<%
	if(serviceOrderID != null) {
%>
<a href="./serviceOrder?id=<%= serviceOrderID %>">... back to service order</a>
<%
	}
%>
<form action='serviceDevice?action=save' method='POST'>
	<table>
		<tr>
			<td>Device</td>
			<td><input type="text" name="device_name" value="<%= fields[0] %>" readonly><%= errorsText[0] %></td>
		</tr>
		<tr>
			<td>Status</td>
			<td>
				<select name="device_status">
		<%
				if(serviceDeviceStatusTypeArray != null)
				for(int k = 0; k < serviceDeviceStatusTypeArray.length; k++) {
					ServiceDeviceStatusType sdst = serviceDeviceStatusTypeArray[k];
					if(fields[1].equals(Integer.toString(sdst.getService_device_status_type()))) {
		%>
						<option value="<%= sdst.getService_device_status_type() %>" selected><%= sdst.getType_name() %></option>
		<%	
					} else {
		%>
						<option value="<%= sdst.getService_device_status_type() %>"><%= sdst.getType_name() %></option>
		<%	
					}
				}
		%>
		</select>
		</td>
		</tr>
		<tr>
			<td>Description</td>
			<td><textarea name="description"><%= fields[2]%></textarea></td>
		</tr>
	</table>
	<input type="submit" name="actionButton" value="Save"/> <%= success %>
</form>
</body>
</html>